package com.bym.controller;

import com.bym.common.TableId;
import com.bym.order.OrderInfo;
import com.bym.service.IOrderService;
import com.bym.vo.PageSimpleOrderDetail;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <h1>订单服务对外 HTTP 接口</h1>
 */
@Api(tags = "订单服务")
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService iOrderService;

    @ApiOperation(value = "创建", notes = "购买(分布式事务): 创建订单 -> 扣减库存 -> 扣减余额 -> 发送物流信息",
            httpMethod = "POST")
    @PostMapping("/create-order")
    public TableId createOrder(@RequestBody OrderInfo orderInfo) {
        return iOrderService.createOrder(orderInfo);
    }

    @ApiOperation(value = "订单信息", notes = "获取当前用户的订单信息：带有分页", httpMethod = "GET")
    @GetMapping("/order-detail")
    public PageSimpleOrderDetail getSimpleOrderDetailByPage(
            @RequestParam(required = false, defaultValue = "1") int page) {
        return iOrderService.getSimpleOrderDetailByPage(page);
    }
}
